package com.example.study.service.impl;

import com.example.study.entity.Student;
import com.example.study.entity.Teacher;
import com.example.study.repository.TeacherRepository;
import com.example.study.service.ITeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 功能描述：
 *
 * @Author: liqiancheng
 * @Email: liqiancheng@centfor.com
 * @Date: 2020/6/4 15:46
 **/
@Service
public class TeacherServiceImpl implements ITeacherService {

    @Resource
    private TeacherRepository teacherRepository;


    @Override
    public Teacher save(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public Teacher update(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public void delete(int id) {
        teacherRepository.deleteById(id);
    }

    @Override
    public List<Teacher> List() {
        Iterator<Teacher> teacherIterator = teacherRepository.findAll().iterator();
        List<Teacher> teacherList = new ArrayList<>();
        while (teacherIterator.hasNext()) {
            teacherList.add(teacherIterator.next());
        }
        return teacherList;
    }
}
